<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="" prop="switch1">
      <el-input v-model="dataForm.switch1" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch2">
      <el-input v-model="dataForm.switch2" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch3">
      <el-input v-model="dataForm.switch3" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch4">
      <el-input v-model="dataForm.switch4" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch5">
      <el-input v-model="dataForm.switch5" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch6">
      <el-input v-model="dataForm.switch6" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch7">
      <el-input v-model="dataForm.switch7" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch8">
      <el-input v-model="dataForm.switch8" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch9">
      <el-input v-model="dataForm.switch9" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch10">
      <el-input v-model="dataForm.switch10" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch11">
      <el-input v-model="dataForm.switch11" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch12">
      <el-input v-model="dataForm.switch12" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch13">
      <el-input v-model="dataForm.switch13" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch14">
      <el-input v-model="dataForm.switch14" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch15">
      <el-input v-model="dataForm.switch15" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch16">
      <el-input v-model="dataForm.switch16" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch17">
      <el-input v-model="dataForm.switch17" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch18">
      <el-input v-model="dataForm.switch18" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch19">
      <el-input v-model="dataForm.switch19" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="" prop="switch20">
      <el-input v-model="dataForm.switch20" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="创建人id" prop="createId">
      <el-input v-model="dataForm.createId" placeholder="创建人id"></el-input>
    </el-form-item>
    <el-form-item label="创建用户姓名" prop="createName">
      <el-input v-model="dataForm.createName" placeholder="创建用户姓名"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="修改人id" prop="updateId">
      <el-input v-model="dataForm.updateId" placeholder="修改人id"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="updateTime">
      <el-input v-model="dataForm.updateTime" placeholder="修改时间"></el-input>
    </el-form-item>
    <el-form-item label="修改用户姓名" prop="updateName">
      <el-input v-model="dataForm.updateName" placeholder="修改用户姓名"></el-input>
    </el-form-item>
    <el-form-item label="版本号" prop="version">
      <el-input v-model="dataForm.version" placeholder="版本号"></el-input>
    </el-form-item>
    <el-form-item label="删除标识 -1：删除 0：正常" prop="gcFlag">
      <el-input v-model="dataForm.gcFlag" placeholder="删除标识 -1：删除 0：正常"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          switch1: '',
          switch2: '',
          switch3: '',
          switch4: '',
          switch5: '',
          switch6: '',
          switch7: '',
          switch8: '',
          switch9: '',
          switch10: '',
          switch11: '',
          switch12: '',
          switch13: '',
          switch14: '',
          switch15: '',
          switch16: '',
          switch17: '',
          switch18: '',
          switch19: '',
          switch20: '',
          createId: '',
          createName: '',
          createTime: '',
          updateId: '',
          updateTime: '',
          updateName: '',
          version: '',
          gcFlag: ''
        },
        dataRule: {
          switch1: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch2: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch3: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch4: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch5: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch6: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch7: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch8: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch9: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch10: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch11: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch12: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch13: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch14: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch15: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch16: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch17: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch18: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch19: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          switch20: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          createId: [
            { required: true, message: '创建人id不能为空', trigger: 'blur' }
          ],
          createName: [
            { required: true, message: '创建用户姓名不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          updateId: [
            { required: true, message: '修改人id不能为空', trigger: 'blur' }
          ],
          updateTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ],
          updateName: [
            { required: true, message: '修改用户姓名不能为空', trigger: 'blur' }
          ],
          version: [
            { required: true, message: '版本号不能为空', trigger: 'blur' }
          ],
          gcFlag: [
            { required: true, message: '删除标识 -1：删除 0：正常不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/buss/bussswitch/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.switch1 = data.bussswitch.switch1
                this.dataForm.switch2 = data.bussswitch.switch2
                this.dataForm.switch3 = data.bussswitch.switch3
                this.dataForm.switch4 = data.bussswitch.switch4
                this.dataForm.switch5 = data.bussswitch.switch5
                this.dataForm.switch6 = data.bussswitch.switch6
                this.dataForm.switch7 = data.bussswitch.switch7
                this.dataForm.switch8 = data.bussswitch.switch8
                this.dataForm.switch9 = data.bussswitch.switch9
                this.dataForm.switch10 = data.bussswitch.switch10
                this.dataForm.switch11 = data.bussswitch.switch11
                this.dataForm.switch12 = data.bussswitch.switch12
                this.dataForm.switch13 = data.bussswitch.switch13
                this.dataForm.switch14 = data.bussswitch.switch14
                this.dataForm.switch15 = data.bussswitch.switch15
                this.dataForm.switch16 = data.bussswitch.switch16
                this.dataForm.switch17 = data.bussswitch.switch17
                this.dataForm.switch18 = data.bussswitch.switch18
                this.dataForm.switch19 = data.bussswitch.switch19
                this.dataForm.switch20 = data.bussswitch.switch20
                this.dataForm.createId = data.bussswitch.createId
                this.dataForm.createName = data.bussswitch.createName
                this.dataForm.createTime = data.bussswitch.createTime
                this.dataForm.updateId = data.bussswitch.updateId
                this.dataForm.updateTime = data.bussswitch.updateTime
                this.dataForm.updateName = data.bussswitch.updateName
                this.dataForm.version = data.bussswitch.version
                this.dataForm.gcFlag = data.bussswitch.gcFlag
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/buss/bussswitch/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'switch1': this.dataForm.switch1,
                'switch2': this.dataForm.switch2,
                'switch3': this.dataForm.switch3,
                'switch4': this.dataForm.switch4,
                'switch5': this.dataForm.switch5,
                'switch6': this.dataForm.switch6,
                'switch7': this.dataForm.switch7,
                'switch8': this.dataForm.switch8,
                'switch9': this.dataForm.switch9,
                'switch10': this.dataForm.switch10,
                'switch11': this.dataForm.switch11,
                'switch12': this.dataForm.switch12,
                'switch13': this.dataForm.switch13,
                'switch14': this.dataForm.switch14,
                'switch15': this.dataForm.switch15,
                'switch16': this.dataForm.switch16,
                'switch17': this.dataForm.switch17,
                'switch18': this.dataForm.switch18,
                'switch19': this.dataForm.switch19,
                'switch20': this.dataForm.switch20,
                'createId': this.dataForm.createId,
                'createName': this.dataForm.createName,
                'createTime': this.dataForm.createTime,
                'updateId': this.dataForm.updateId,
                'updateTime': this.dataForm.updateTime,
                'updateName': this.dataForm.updateName,
                'version': this.dataForm.version,
                'gcFlag': this.dataForm.gcFlag
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
